<%- include('nav') %>
<div class="text-sm breadcrumbs">
  <ul>
    <li>
      <a href="/admin/home">首页</a>
    </li>
    <li>设置</li>
  </ul>
</div>

<div class="flex">
  <a class="btn btn-primary btn-small" href="/admin/page/redeem_new">新建</a>
  <div style="flex: 1"></div>
  <a class="btn btn-default btn-small" target="_blank" href="/admin/redeems/export">导出</a>
</div>
<div id="app" class="clearfix">
  <div class="col col-12 p1">
    <table class="table col-12 table-zebra table-compact black">
      <thead>
        <th>code</th>
        <th>描述</th>
        <th>兑换时间</th>
        <th>群聊</th>
      </thead>
      <tbody>
        <tr v-for="redeem in redeems">
          <td>{{redeem.code}}</td>
          <td>{{redeem.title}}</td>
          <td>{{redeem.redeemTime|datetime}}</td>
          <td>{{redeem.topic}}</td>
        </tr>
      </tbody>
    </table>
  </div>
</div>

<script>
  new Vue({
    el: "#app",
    data: function () {
      return { redeems: [] };
    },
    created: function () {
      this.getRedeems();
    },
    filters: {
      datetime: function (time) {
        if (!time) return "";
        return dayjs(time).format("YYYY-MM-DD HH:mm:ss");
      },
    },
    methods: {
      getRedeems: function () {
        let that = this;
        axios.get("/admin/redeems").then(function (res) {
          that.redeems = res.data.redeems;
        });
      },
    },
  });
</script>
